#include "HUD.h"
#include "RessourceManager.h"
#include "Constants.h"

HUD::HUD()
{
    lifebar.setTexture(*RessourceManager::getTexture("lifebar.png"));
    lifebarFrame.setTexture(*RessourceManager::getTexture("lifebarframe.png"));

    lifebar.setPosition(WINDOW_WIDTH - 345, 35);
    lifebarFrame.setPosition(WINDOW_WIDTH - 350, 30);

    lifeText.setFont(*RessourceManager::getFont("font.ttf"));
    lifeText.setCharacterSize(20);
    lifeText.setColor(sf::Color(255,255,255,255));
}

void HUD::updateLife(int hp, int maxHp)
{
    lifebar.setTextureRect(sf::IntRect(0, 0, 300*hp/maxHp, 20));
    std::string sHP, sMaxHP;
    ss << hp;
    sHP = ss.str();
    ss.str("");
    ss << maxHp;
    sMaxHP = ss.str();
    ss.str("");

    lifeText.setString(sHP + "/" + sMaxHP);
    lifeText.setPosition(WINDOW_WIDTH - 173 - lifeText.getGlobalBounds().width, 35);

}

void HUD::render(sf::RenderWindow* w)
{
    w->setView(w->getDefaultView());
    w->draw(lifebar);
    w->draw(lifebarFrame);
    w->draw(lifeText);
}
